package com.raos.spring2rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 消息监听器
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/6/18 21:05
 */
@Component
public class MessageListener {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * 监听邮件队列
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "spring.test.queue_email", durable = "true"),
            exchange = @Exchange(
                    value = "spring.test.exchange",
                    ignoreDeclarationExceptions = "true",
                    type = ExchangeTypes.TOPIC
            ),
            key = {"#.#"}))
    public void receiveEmail(String msg) {
        log.info("[邮箱服务]接收到消息：【{}】", msg);
    }

    /**
     * 监听短信队列
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "spring.test.queue_sms", durable = "true"),
            exchange = @Exchange(
                    value = "spring.test.exchange",
                    ignoreDeclarationExceptions = "true",
                    type = ExchangeTypes.TOPIC
            ),
            key = {"topic.#.sms.#"}))
    public void receiveSms(String msg) {
        log.info("[短信服务]接收到消息：【{}】", msg);
    }

}
